// 记忆函数的本质不就是--闭包？
// 记忆函数的功能，根据变量名，缓存当前函数处理结果
const _ = require('lodash')

function getArea (r) {
  console.log(r)
  return Math.PI * r * r
}

// let getAreaWithMemory = _.memoize(getArea)
// console.log(getAreaWithMemory(4))
// console.log(getAreaWithMemory(4))
// console.log(getAreaWithMemory(4))

let memorize = function(fun){
    let obj = {}
    return function (){
        obj[JSON.stringify(fun)] = fun.apply(this, arguments)
        return  obj[JSON.stringify(fun)]
    }
}

let testMemorize= memorize((item)=>{return item * item})

console.log(testMemorize(4))
console.log(testMemorize(4))
console.log(testMemorize(4))